package com.ruoyi.web.controller.function;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.entity.VitalSigns;
import com.ruoyi.system.service.VitalSignsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Y·C
 * @version 1.0.0
 * @ClassName VitalSignsController.java
 * @Description TODO
 * @createTime 2023年11月19日 19:48:00
 */
@Api(tags = "生命体征接口")
@RestController
@RequestMapping("/vitalSigns")
public class VitalSignsController extends BaseController {


    @Autowired
    private VitalSignsService vitalSignsService;


    /**
     * 根据vitalId获取生命体征信息
     * */
    @ApiOperation(value = "根据vitalId获取生命体征信息")
    @GetMapping("/getVitalSignsById/{vitalId}")
    @Anonymous
    public AjaxResult getVitalSignsById(@PathVariable("vitalId") Long vitalId) {
        VitalSigns vitalSigns = vitalSignsService.getVitalSignsByFacilityId(vitalId);
        return AjaxResult.success(vitalSigns);
    }

    /**
     * 查询生命体征列表
     * */
    @ApiOperation(value = "查询生命体征列表")
    @GetMapping("/getVitalSignsList")
    @Anonymous
    public TableDataInfo getVitalSignsList( VitalSigns vitalSigns) {
        startPage();
        List<VitalSigns> vitalSignsList =  vitalSignsService.getVitalSignsList(vitalSigns);
        return getDataTable(vitalSignsList);
    }

    /**
     * 根据隔离人员id获取生命体征信息
     * */
    @ApiOperation(value = "根据隔离人员id获取生命体征信息")
    @GetMapping("/getVitalSignsByIsolationId/{userId}")
    @Anonymous
    public AjaxResult getVitalSignsByIsolationId(@PathVariable("userId") Long userId) {
       List<VitalSigns> vitalSignsList = vitalSignsService.getVitalSignsByIsolationId(userId);
        return AjaxResult.success(vitalSignsList);
    }

    /**
     * 删除多条生命体征信息
     * */
    @ApiOperation(value = "删除多条生命体征信息")
    @DeleteMapping("/deleteVitalSignsByIds")
    @Anonymous
    public AjaxResult deleteVitalSignsByIds(@RequestBody List<Long> ids) {
        return AjaxResult.success(vitalSignsService.removeByIds(ids));
    }

    /**
     * 新增生命体征信息
     * */
    @ApiOperation(value = "新增生命体征信息")
    @PostMapping("/addVitalSigns")
    @Anonymous
    public AjaxResult addVitalSigns(@RequestBody VitalSigns vitalSigns) {
        return AjaxResult.success(vitalSignsService.save(vitalSigns));
    }

    /**
     * 修改生命体征信息
     * */
    @ApiOperation(value = "修改生命体征信息")
    @PutMapping("/updateVitalSigns")
    @Anonymous
    public AjaxResult updateVitalSigns(@RequestBody VitalSigns vitalSigns) {
        return AjaxResult.success(vitalSignsService.updateById(vitalSigns));
    }

    /**
     * 导出生命体征信息
     * */
    @ApiOperation(value = "导出生命体征信息")
    @RequestMapping("/export")
    @Anonymous
    public void export(HttpServletResponse response, VitalSigns vitalSigns) {
        List<VitalSigns> vitalSignsList = vitalSignsService.getVitalSignsList(vitalSigns);
        ExcelUtil<VitalSigns> util = new ExcelUtil<VitalSigns>(VitalSigns.class);
        util.exportExcel(response,vitalSignsList, "生命体征数据");
    }


}

